import { createRouter, createWebHistory } from 'vue-router'
import routes from "./routes";

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, from,next) => {

  const isLogin  = JSON.parse(localStorage.getItem('isLogin'))
  if(!isLogin){
    if(to.name === 'login' || to.name === 'register'){
      next()
    }else {
      next('/login')
    }
  }else {
    next()
  }
})

export default router
